package com.liwenfeng.bigevent.service.impl;

import com.liwenfeng.bigevent.mapper.UserMapper;
import com.liwenfeng.bigevent.pojo.User;
import com.liwenfeng.bigevent.service.UserService;
import com.liwenfeng.bigevent.utils.Md5Util;
import com.liwenfeng.bigevent.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public User getByName(String username){
        return userMapper.getByName(username);
    }

    @Override
    public void insertUser(String username, String password) {
        userMapper.insertUser(username, Md5Util.getMD5String(password));
    }

    @Override
    public void update(User user) {
        user.setUpdateTime(LocalDateTime.now());
        userMapper.update(user);
    }

    @Override
    public void updateAvatar(String url ) {
        Map<String,Object> claims = ThreadLocalUtil.get();
        Integer id = (Integer) claims.get("id");
        userMapper.updateAvatar(url,id);
    }

    @Override
    public void updatePwd(String newPwd,Integer id) {
        userMapper.updatePwd(newPwd,id);
    }
}
